package com.woniu;

import java.sql.SQLOutput;
import java.util.Scanner;

/**
 * @author 杨光 微信号:tolryg
 * @time 16:02
 */
public class Main {

    //要求：
    /*
求某年当中第n天的日期，n从1开始计数。
输入是两个整数，第一个是年份，第二个是n
输出是一个yyyyMMdd格式的日期字符串
把上面的程序中getDateOfNthDayInYear函数补充完整，

     */

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int year = in.nextInt();
            int n = in.nextInt();
            int date =getDateOfNthDayInYear(year,n);
            System.out.println(date);
        }
    }

    private static int getDateOfNthDayInYear(int year, int n) {
        int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        if (isLeapYear(year)) {
            daysInMonth[1] = 29;
        }

        int totalDays = 0;
        int month = 0;
        while (n > totalDays + daysInMonth[month]) {
            totalDays += daysInMonth[month];
            month++;
        }

        int day = n - totalDays;

        return Integer.parseInt(year + String.format("%02d", month+1) + String.format("%02d", day));
    }
    private static boolean isLeapYear(int year) {
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                if (year % 400 == 0) return true;
                else return false;
            } else return true;
        } else {
            return false;
        }
    }
}
